///////////////////////////////////////////////////////////////////////////////
// Name:        common.h
// Purpose:     Common header
// Copyright:   (c) 2006, Ivan Laptev, TT Solutions
// License:     GPL, Please contact us for commercial license.
//              http://www.tt-solutions.com/
///////////////////////////////////////////////////////////////////////////////
#ifndef OBJECTDET_COMMON_H_
#define OBJECTDET_COMMON_H_

#if defined HAVE_CONFIG_H // Using autoconf.
#   include "objectdet/config.h"
#endif // Not using autoconf.

#ifdef DLL_EXPORT
#    define IMPEXP __declspec(dllexport)
#else
#  ifdef USE_NPLATES
#    define IMPEXP __declspec(dllimport)
#  else
#    define IMPEXP
#  endif
#endif

// STL headers
#include <iostream>
#include <list>
#include <sstream>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>

// Boost headers
#include <boost/lexical_cast.hpp>
#include <boost/tuple/tuple.hpp>

#include "objectdet/opencv.h"
#include "objectdet/profiling.h"

// OpenCV GUI headers
#include <highgui.h>

enum PixClass
{
    ORIENTGRAD_DNUM4,
    TEXTONS_SC12_GDORDER2
};

// Rule type. Starts with 1 for backward compatibility (existing xml files).
enum StageRuleType
{
    SrtOneSquare = 1,
    SrtTwoCols,
    SrtTwoRows,
    SrtFourQuarters,
    SrtDummyMax
};

struct StageRule
{
    StageRuleType   type;

    std::vector<double> W;
    double              b;

    double  separab;

    size_t left;
    size_t top;
    size_t width;
    size_t height;

    // some cached variables to speed up the process of calculation of the features
    mutable bool    cached;
    mutable size_t cached_w;
    mutable size_t cached_h;
    mutable size_t cached_corner_1to2_shift;
    mutable size_t cached_corner_1to3_shift;
    mutable size_t cached_corner_1to4_shift;

    double  trainerror;
    // DModelRule_Size size;

    double  Alpha;
    double  Z;
    double  WeightedErr;
    double  ErrBound;

    StageRule() : cached(false) {}
    void clear_cache() const
    {
        cached = false;
    }
};

typedef std::vector<StageRule> StageRules;
struct Stage
{
    StageRules  rules;
    int         exitflag;
    double      stage_threshold;
	size_t      histblock_winsize_x;
	size_t      histblock_winsize_y;
	size_t      histblock_size_x;
	size_t      histblock_size_y;
	std::string histtype;
};

typedef std::vector<Stage> Model;

#endif // OBJECTDET_COMMON_H_

